package com.neuronbit.businessflow.intellij.model;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * The type Formatted method.
 */
@Getter
public class FormattedMethodString {
    private final String value;
    private String returnType;
    private String name;
    private String[] parameterTypes;

    /**
     * Instantiates a new Formatted method.
     *
     * @param value the formatted method
     */
    public FormattedMethodString(String value) {
        this.value = value;
        if (StringUtils.isNotBlank(value)) {
            name = StringUtils.strip(StringUtils.substringBefore(value, "("));
            List<String> list = new ArrayList<>();
            for (String arg : StringUtils.substringBetween(value, "(", ")").split(",")) {
                String s = StringUtils.substringBefore(StringUtils.strip(arg), " ");
                list.add(s);
            }
            parameterTypes = list.toArray(new String[0]);
            returnType = StringUtils.strip(StringUtils.substringAfter(value, ":"));
        }
    }

    public boolean isBlank() {
        return StringUtils.isBlank(value);
    }
}
